<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/6/2
 * Time: 14:05
 */

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\GoodsBasicInfo as mGoodsBasicInfo;

$data = mGoodsBasicInfo::select(['goods_id','category_id','second_category_id','third_category_id','four_category_id'],['last_category_id'=>0]);
if (!$data){
    var_dump('暂无需要修复的数据');die;
}
foreach ($data as  $val){

    $result['last_category_id'] = $val['category_id'];
    if ($val['four_category_id']){

        $result['last_category_id'] = $val['four_category_id'];

    } else if($val['third_category_id']) {

        $result['last_category_id'] = $val['third_category_id'];

    } else if($val['second_category_id']) {

        $result['last_category_id'] = $val['second_category_id'];
    }

    $where = ['goods_id'=>$val['goods_id']];

    $ret = mGoodsBasicInfo::update($result, $where);

    if ($ret->rowCount())
    {
        var_dump('执行成功goodsId='.$val['goods_id']);
    } else {
        var_dump('执行失败goodsId='.$val['goods_id']);
    }

}

